

from tjango.ajax_select.fields import autoselect_fields_check_can_add
from django.contrib import admin


def get_inline(f, request):
    
    f = inline.get_formset(request, obj)(request)
    autoselect_fields_check_can_add(f, f.model, request.user)
    return f

class AjaxSelectAdmin(admin.ModelAdmin):
    
    """ in order to get + popup functions subclass this or do the same hook inside of your get_form """
    
    def get_form(self, request, obj=None, **kwargs):
        form = super(AjaxSelectAdmin,self).get_form(request,obj,**kwargs)
        
        autoselect_fields_check_can_add(form,self.model,request.user)
        return form


#    def get_formsets(self, request, obj=None):
#        for inline in self.inline_instances:
#            formset = lambda request: get_inline(f, request)
                
				#for f in formset.forms:
				#	autoselect_fields_check_can_add(f, f.model, request.user)
#            yield formset
        
